package com.kechen.servlet;

import com.kechen.dao.EmpDao;
import com.kechen.pojo.Employee;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebServlet("/add")

public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String name= request.getParameter("name");
        String age=request.getParameter("age");
        Employee employee = new Employee();
        employee.setName(name);
        employee.setAge(age);

        EmpDao dao=new EmpDao();
        dao.insertEmp(employee);

        response.sendRedirect("GetServlet");

    }
}
